package com.history.app;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

public class GridLine {
	JTable table;

	public static void main(String[] args) {
		String data[][] = {{"Vinod","Computer","3"},
				   {"Rahul","History","2"},
				   {"Manoj","Biology","4"},
				   {"Sanjay","PSD","5"}};
		new GridLine(data);
	}


	String col[] = {"Id", "Title", "Content", "Update Date" };
	
	public GridLine(String data[][]) {
		JFrame frame = new JFrame("Grid Line in JTable Component!");
		JPanel panel = new JPanel();
		DefaultTableModel model = new DefaultTableModel(data, col);
		table = new JTable(model);
		// Setting the grid line
		table.setShowGrid(true);
		// Removing the grid line from the table
		// table.setShowGrid(false);
		// Show vertical grid lines
		table.setShowVerticalLines(true);
		// setting grid color
		table.setGridColor(Color.red);
		
		table.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				int srow = table.getSelectedRow();
				String id 		= (String)table.getValueAt(srow, 0);
				System.out.println("mouse press = " + id);
				TextAreaDemo sdd = TextAreaDemo.getInstance();
				sdd.setArticle(id);
				sdd.showArticle(true);
			}
			
			@Override
			public void mouseExited(MouseEvent e) {}
			
			@Override
			public void mouseEntered(MouseEvent e) {}
			
			@Override
			public void mouseClicked(MouseEvent e) {}
		});
		
		JTableHeader header = table.getTableHeader();
		header.setBackground(Color.yellow);
		JScrollPane pane = new JScrollPane(table);
		panel.add(pane);
		frame.add(panel);
		frame.setSize(800, 450);
		frame.setUndecorated(true);
		frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}